﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BaFangSpider.Stock;

namespace BaFangSpider
{
    public partial class MainForm : Form
    {
        private bool shouldExit = false;
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            shouldExit = true;
            Application.Exit();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.WindowState != FormWindowState.Normal)
            {
                this.Show();
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                if (!this.Focused)
                {
                    this.TopMost = true;
                    this.Focus();
                    this.TopMost = false;
                }
                else
                {
                    this.WindowState = FormWindowState.Minimized;
                }
            }
        }

        private void MainForm_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.Hide();
            }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!shouldExit)
            {
                e.Cancel = true;
                this.WindowState = FormWindowState.Minimized;
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            //AppleStoreMonitorService.GetInstance().Start();
            //QQOnlineMonitorService.GetInstance().Start();
            WeatherMonitorService.GetInstance().Start();
            //StockMonitorService.GetInstance().Start();
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            AppleStoreMonitorService.GetInstance().Stop();
            QQOnlineMonitorService.GetInstance().Stop();
            WeatherMonitorService.GetInstance().Stop();
            StockMonitorService.GetInstance().Stop();
        }
    }
}
